/**
* Copyright (c) 2004-2005 Luciano Xumerle. All rights reserved.
*
* This file is part of gephinfo.
*
* gephinfo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
 * COMPILE:
 * javac -classpath jenoware.jar JoinCSV.java
 *
 * EXECUTE:
 * java -classpath jenoware.jar JoinCSV file1.csv file2.csv ...
 *
 * The program join tables retrieved from several csv files.
 *
 */

// import jenoware packages
import it.ciano.jenoware.*;

public class JoinCSV {
    public JoinCSV() {}

    public static void main ( String[] args )
    throws java.io.IOException {

        System.err.println ( "The programs joins multiple csv file." );
        System.err.println ( "Default separator is ';'." );
        System.err.println ( "Use the option '-t' to set <TAB> as separator." );

        String sep=";";
        // the Pedigree object
        Pedigree ped = new Pedigree();
        // add all the CSV files to the Pedigree
        for ( int i = 0; i < args.length; i++ )
            if ( args[ i ].equals ( "-t" )  )
                sep="\t";
            else
                toPedigree.importCSV ( ped, args[ i ], sep );

        // print Phenotype list
        String[] phnt = ped.getPhenotypesList();
        if ( phnt != null ) {
            System.err.println ( "Printing Phenotype:" );
            for ( int i = 0; i < phnt.length; i++ )
                System.err.println ( " -> " + phnt[ i ] );
        }
        // print markers statistics
        String[] markers = ped.getMarkersList();
        if ( markers != null ) {
            System.err.println ( "Printing Genotype Statistics:\n" );
            for ( int i = 0; i < markers.length; i++ ) {
                System.err.println ( ped.pedCheck ( markers[ i ] ) );
                // MarkerFreq ll = new MarkerFreq( ped, markers[ i ] );
                // System.err.println( ll );
            }
        }

        // print the CSV file
        System.err.println ( "Printing CSV:\n" );
        System.out.print ( ( new GetCSV ( ped, sep, true, true ) ).toString() );

    } // end main

} //end class

